package com.sping_boot3.spirng_boot3.config;

import com.sping_boot3.spirng_boot3.handler.UserHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;

@Configuration
public class UserConfig {

    @Bean
    public RouterFunction<ServerResponse> userRoute(UserHandler userHandler) {
        return RouterFunctions.route() // 开始定义路由信息
                .GET("/user/{id}", RequestPredicates.accept(MediaType.ALL), userHandler::getUserById)
                .GET("/user/list", userHandler::getUserList)
                .POST("/user/add", RequestPredicates.accept(MediaType.APPLICATION_JSON), userHandler::addUser)
                .POST("/user/del", userHandler::delUser)
                .build();
    }
}
